//
//  MainViewController.swift
//  微博
//
//  Created by 呆仔～林枫 on 16/3/6.
//  Copyright © 2016年 呆仔～林枫. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabbar = MainTabbar()
        print(tabBar.classForCoder)
        setValue(mainTabbar, forKey: "tabBar")
        print(tabBar.classForCoder)
        
        addChildViewControllers()
    }

    private func addChildViewControllers(){
        addChildViewController(HomeTableViewController(),title:"首页",imageName:"tabbar_home")
        addChildViewController(MessageTableViewController(),title:"消息",imageName:"tabbar_message_center")
        addChildViewController(DiscoverTableViewController(),title:"发现",imageName:"tabbar_discover")
        addChildViewController(ProfileTableViewController(),title:"我",imageName:"tabbar_profile")
        
    }
    
    private func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        vc.title = title
        vc.tabBarItem.title = title
        
        tabBar.tintColor = .orangeColor()
        vc.tabBarItem.image = UIImage(named:imageName)
        vc.tabBarItem.selectedImage = UIImage(named:imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    



}
